/*
 * @(#)UserDaoImpl.java	2013-1-31 下午4:31:59
 * order_jsp_servlet
 * Copyright 2013 Thuisoft, Inc. All rights reserved.
 * THUNISOFT PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */
package com.thunisoft.order.dao.impl;

import com.thunisoft.order.common.utils.MyTemplate;
import com.thunisoft.order.dao.IUserDao;
import com.thunisoft.order.domain.TUser;

/**
 * UserDaoImpl
 * 
 * @author ice
 * @version 1.0
 * 
 */
public class UserDaoImpl extends MyTemplate implements IUserDao {

    @Override
    public boolean login(TUser user) {
        StringBuilder sbHql = new StringBuilder();
        sbHql.append("select    ");
        sbHql.append("  count(*)    ");
        sbHql.append("from  ");
        sbHql.append("  TUser user  ");
        sbHql.append("where ");
        sbHql.append("  user.username = ?   ");
        sbHql.append("      and ");
        sbHql.append("  user.password = ?");
        return getHibernateTemplate().find(sbHql.toString(),
                new Object[] { user.getUsername(), user.getPassword() }).size() > 0 ? true
                : false;
    }

    @Override
    public boolean checkUserExist(String sUsername) {
        StringBuilder sbHql = new StringBuilder();
        sbHql.append("select    ");
        sbHql.append("  count(*)    ");
        sbHql.append("from  ");
        sbHql.append("  TUser user  ");
        sbHql.append("where ");
        sbHql.append("  user.username = ?");
        return getHibernateTemplate().find(sbHql.toString(),
                new Object[] { sUsername }).size() > 0 ? true : false;
    }
}
